﻿using IM.Easy.Core.ServiceLifetime;
using IM.Easy.Core.Services;
using IM.Easy.Core.Utils;
using IM.Easy.Infrastructure.Query;
using IM.Easy.Entity.Authorization;
using IM.Easy.AuthorizationServices.Dtos;

namespace IM.Easy.AuthorizationServices.IServices
{
    public interface IRefreshTokenService : IAppServices<RefreshToken>
    {
        /// <summary>
        /// 创建一个新实体
        /// </summary>
        /// <param name="entity">要创建的实体</param>
        /// <returns>创建后的实体</returns>
        RefreshToken Create(RefreshToken entity);

        /// <summary>
        /// 根据 ID 获取实体
        /// </summary>
        /// <param name="id">实体的唯一标识</param>
        /// <returns>获取的实体</returns>
        RefreshToken GetById(long id);

        /// <summary>
        /// 获取所有实体
        /// </summary>
        /// <returns>所有实体的列表</returns>
        PageResponse<RefreshToken> GetPageList(RefreshTokenQueryDto query);

        /// <summary>
        /// 更新一个已有的实体
        /// </summary>
        /// <param name="entity">更新后的实体</param>
        /// <returns>更新后的实体</returns>
        bool Update(RefreshToken entity);

        /// <summary>
        /// 根据 ID 删除实体
        /// </summary>
        /// <param name="id">要删除的实体的唯一标识</param>
        /// <returns>操作是否成功</returns>
        bool Delete(params long[] key);

        /// <summary>
        /// 生成刷新token
        /// </summary>
        /// <returns></returns>
        RefreshToken Generate();

        /// <summary>
        /// 验证刷新token有效性
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        bool ValidateToken(string token);

        /// <summary>
        /// 吊销刷新令牌
        /// </summary>
        void Revoke(string token, string? replacedByToken = null);

        /// <summary>
        /// 通过刷新token获取token相关信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        long GetUserId(string token);
    }
}
